home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4394 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: gail.ripco.com!mambuhl
  2. From: mambuhl@ripco.com (Martin Ambuhl)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Incrementing enumerat
  5. Date: 4 Feb 1996 00:34:36 GMT
  6. Organization: Ripco Communications, Inc.
  7. Message-ID: <4f0uus$al9@gail.ripco.com>
  8. NNTP-Posting-Host: foley.ripco.com
  9.  
  10. Kimberley Burchett <burchett>
  11. in <4erc78$g0b@mastermind.odi.com> wrote:
  12.  
  13. >Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
  14. >>for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
  15. >>
  16. >>        /* do something */
  17. >>}
  18.  
  19. >  Enums are constants and have no math semantics.      But you can convert
  20. >enums to ints (although not vice versa).  Try replacing EnumeratedType
  21. >with int -- you can increment the int and compare it to enum_first and
  22. >enum_last.  However, you won't be able to pass eIndex to any function
  23. >expecting EnumeratedType w/o explicitly casting it.
  24.  
  25. Since Mr. Law and Ms. Burchett have both posted to comp.lang.c, this
  26. response concerns C.  If they have a non-C (C++) problem, then they
  27. should not post to comp.lang.c.
  28.  
  29. I suggest you reread your C language reference.  A member of an
  30. enumeration is a constant.      If the C++-ism of Mr. Law's example is
  31. corrected:
  32.         EnumeratedType eIndex;
  33.         for (eIndex = enum_first; eIndex < enum_last; eIndex++) {
  34.                 /* do something */
  35.         }
  36. there is no problem.  eIndex is not a member of an enumeration but a
  37. variable of type EnumeratedType.  The constants of the enumeration are
  38. integral constant values, a variable of type EnumeratedType is an
  39. integral variable. "Each enumerated type shall be compatible with an
  40. integer type" (6.5.2.2)
  41.  
  42. >  I have never had a problem with the semantics of enums, and have
  43.  
  44. Yes, you have.
  45.  
  46. >even found it useful that you can't convert int->enum.  If you're
  47. >running into problems, you might consider using a different idiom.
  48.                                                                                                                     
  49. --
  50. * Martin Ambuhl       net: mambuhl@ripco.com
  51. * Chicago, IL (USA)    
  52.